package main

import "fmt"

func main() {
	array := []int{1,5,0,4,7,8,2}
	array = quicksort(array)
	fmt.Println("最小值为:",array[0])
	fmt.Println("最大值为:",array[len(array)-1])
}
func quicksort(arr []int) []int{
	//设置出口
	if len(arr) <= 1{
		return arr
	}
	pivot := arr[len(arr)/2]
	left := make([]int,0)
	middle := make([]int,0)
	right := make([]int,0)
	for _, v := range arr{
		switch{
		case v > pivot:
			right = append(right, v)
		case v == pivot:
			middle = append(middle, v)
		case v < pivot:
			left = append(left, v)
		}
	}
	res := append(quicksort(left), middle...)
	res = append(res, quicksort(right)...)
	return res
}
